package com.gxa.service.impl;

import com.gxa.common.JsonResult;
import com.gxa.common.R;
import com.gxa.dao.HouseDao;
import com.gxa.dao.impl.HouseDaoImpl;
import com.gxa.service.HouseService;

import java.sql.SQLException;
import java.util.List;

public class HouseServiceImpl implements HouseService {
    //创建dao对象
    private HouseDao houseDao = new HouseDaoImpl();
    /**
     * 业务逻辑处理：分页查询房产信息
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Override
    public JsonResult queryHouseList(Integer currentPage, Integer pageSize) {
        //创建JsonResult对象
        JsonResult jsonResult = new JsonResult();
        try {
            //处理currentPage和pageSize
            Integer param01 = (currentPage-1)*pageSize;
            Integer param02 = pageSize;
            //调用dao
            List houseList = houseDao.queryHouseList(param01, param02);
            //总记录数
            Integer count = houseDao.countHouse();
            if(houseList!=null) {//查询成功
                jsonResult.setCode(0);
                jsonResult.setMsg("查询成功");
                jsonResult.setCount(count);
                jsonResult.setData(houseList);
            }else {
                jsonResult.setCode(500);
                jsonResult.setMsg("服务器开小差，请联系管理员");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return jsonResult;
    }
}
